#include "GameObject.h"

#include <cmath>

#include "scenes/GameScene.h"

GameObject::GameObject( GameScene& theGame )
   : Game( theGame ),
     depth( 0 ),
     gravityStrength( 0.f ),
     gravityDirection( 0.f ),
     direction( 0.f ),
     speed( 0.f ),
     mousePressed( false )
{
}

int GameObject::GetDepth() const
{
	return depth;
}

void GameObject::SetDepth( int theDepth )
{
	depth = theDepth;
}

gdn::Vector2f GameObject::GetPosition() const
{
	return sprite.GetPosition();
}

void GameObject::SetPosition( const gdn::Vector2f& thePos )
{
	sprite.SetPosition( thePos );
}

void GameObject::SetPosition( float theX, float theY )
{
	sprite.SetPosition( theX, theY );
}

float GameObject::GetGravityStrength() const
{
	return gravityStrength;
}

void GameObject::SetGravityStrength( float theGravityStrength )
{
	gravityStrength = theGravityStrength;
}

float GameObject::GetGravityDirection() const
{
	return gravityDirection;
}

void GameObject::SetGravityDirection( float theGravityDirection )
{
	gravityDirection = theGravityDirection;
}

float GameObject::GetDirection() const
{
	return direction;
}

void GameObject::SetDirection( float theDirection )
{
	direction = theDirection;
}

float GameObject::GetSpeed() const
{
	return speed;
}

void GameObject::SetSpeed( float theSpeed )
{
	speed = theSpeed;
}

void GameObject::StepEvent()
{
	if ( speed != 0 )
	{
		sprite.Move( cos( gdn::DegreesToRadians( direction ) ) * speed, sin( gdn::DegreesToRadians( direction ) ) * speed );
	}
	Step();
}

void GameObject::StepEvent( const gdn::Event& event )
{
	if ( event.type == gdn::Event::MouseButtonPressed )
	{
		mousePressed = true;
		GlobalMousePress( Game.App.GetWindow().GetInput().GetMousePosition(), event.mouseButton );
	}
	else if ( event.type == gdn::Event::MouseButtonReleased )
	{
		mousePressed = false;
		GlobalMouseRelease( Game.App.GetWindow().GetInput().GetMousePosition(), event.mouseButton );
	}
	else if ( event.type == gdn::Event::MouseMoved )
	{
		GlobalMouseMove( Game.App.GetWindow().GetInput().GetMousePosition() );
	}
	else if ( event.type == gdn::Event::KeyPressed )
	{
		GlobalKeyPress( event.key );
	}
	else if ( event.type == gdn::Event::KeyReleased )
	{
		GlobalKeyRelease( event.key );
	}
}

void GameObject::Draw( gdn::Window& window )
{
	window.Draw( sprite );
}

void GameObject::Step()
{
}

void GameObject::GlobalMousePress( const gdn::Vector2f& clickPos, const gdn::Mouse::Button& clickButton )
{
}

void GameObject::GlobalMouseRelease( const gdn::Vector2f& clickPos, const gdn::Mouse::Button& clickButton )
{
}

void GameObject::GlobalMouseMove( const gdn::Vector2f& mousePos )
{
}

void GameObject::GlobalKeyPress( const gdn::Key::Code key )
{
}

void GameObject::GlobalKeyRelease( const gdn::Key::Code key )
{
}
